package com.quectel.dms.service;

import cn.hutool.system.SystemUtil;
import com.quectel.dms.service.aiotap.AiotapService;
import com.quectel.util.common.OSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 在这里编写说明
 *
 * @author: ryan
 * @email: ryan.ran@quectel.com
 * @date: 2023-08-16 13:23:00
 */

@Component
@Slf4j
public class AiotApStarter implements ApplicationRunner {

    @Autowired
    private AiotapService aiotapService;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (SystemUtil.getOsInfo().isWindows() || OSUtils.isRedhatRelease() || OSUtils.isDebianRelease()) {
            Thread aiotApServeThread = new Thread(() -> {
                try {
                    aiotapService.init();
                } catch (Exception e) {
                    log.error("AiotAp server error", e);
                }
            });
            aiotApServeThread.setName("Aiotap tcp server");
            aiotApServeThread.setDaemon(Boolean.TRUE);
            aiotApServeThread.start();
        }
    }
}
